package com.ss.android.newmedia.message;

import android.content.Context;

import com.bytedance.common.plugin.interfaces.pushmanager.PushChannelHelper;
import com.bytedance.common.plugin.interfaces.pushmanager.PushCommonConstants;
import com.bytedance.common.plugin.interfaces.pushmanager.client.SsPushManager;
import com.bytedance.common.plugin.interfaces.pushmanager.setting.PushCommonSetting;
import com.bytedance.common.plugin.interfaces.pushmanager.setting.PushSetting;
import com.bytedance.common.utility.Logger;

import java.util.HashMap;
import java.util.Map;

public class o {
    private static volatile o a;
    private Context b;
    private volatile boolean c;

    private o(Context arg2) {

        this.c = false;
        this.b = arg2.getApplicationContext();
    }

    public static o a(Context arg2) {
        if (o.a == null) {
            Class v1 = o.class;
            synchronized (v1) {
                if (o.a == null) {
                    o.a = new o(arg2);
                }
            }
        }

        return o.a;
    }

    static Context a(o arg1) {
        return arg1.b;
    }

    static void a(o arg0, Context arg1, String arg2) {
        arg0.a(arg1, arg2);
    }

    static boolean b(o arg1) {
        arg1.c = false;
        return false;
    }

    public final synchronized void a(Context arg5, Map arg6, boolean arg7) {
        int v0_2;
        Logger.d("PushConfigHelper", "handleAppLogUpdate() called ssidsMap = [" + arg6 + "] isRequestingUpdateSender = " + this.c);
        if (!arg6.isEmpty()) {
            Object v0_1 = arg6.get(PushCommonConstants.KEY_CLIENTUDID);
            Object v1 = arg6.get(PushCommonConstants.KEY_DEVICE_ID);
            Object v2 = arg6.get(PushCommonConstants.KEY_INSTALL_ID);
            if (android.support.design.a.isTextEmpty(((String) v0_1))) {
                v0_2 = 0;
            } else if (android.support.design.a.isTextEmpty(((String) v1))) {
                v0_2 = 0;
            } else if (!android.support.design.a.isTextEmpty(((String) v2))) {
                PushSetting.getInstance().saveSSIDs(arg6);
                v0_2 = 1;
            } else {
                v0_2 = 0;
            }
        } else {
            v0_2 = 0;
        }
        if (v0_2 != 0 && !this.c && System.currentTimeMillis() - PushSetting.getInstance().getLastGetUpdateSenderTimeMil() > (((long) (PushSetting.getInstance().getUpdateSenderIntervalTimeSecond() * 1000))) || (arg7)) {
            this.c = true;
            new p(this, arg5).start();
        } else if (!this.c) {
            this.a(this.b, PushSetting.getInstance().getPushChannelsJsonArray());
        }
    }

    private synchronized void a(Context arg8, String arg9) {
        HashMap v3 = new HashMap();
        PushCommonSetting.getInstance().getSSIDs(((Map) v3));
        Object v0_1 = ((Map) v3).get(PushCommonConstants.KEY_CLIENTUDID);
        Object v1 = ((Map) v3).get(PushCommonConstants.KEY_DEVICE_ID);
        Object v2 = ((Map) v3).get(PushCommonConstants.KEY_INSTALL_ID);
        if (Logger.debug()) {
            Logger.d("PushConfigHelper", "tryRegistAllpush tryRegistAllpush = " + arg9 + " ssidsMap = " + v3);
        }

        if (!PushChannelHelper.getInstance().hasSupportChannel(arg9)) {
            arg9 = PushSetting.getInstance().getPushChannelsJsonArray();
            if (!PushChannelHelper.getInstance().hasSupportChannel(arg9)) {
                Logger.d("PushConfigHelper", "tryRegistAllpush: 没有可用通道");
                return;
            }

        }
        PushSetting.getInstance().setPushChannelsJsonArray(arg9);
        if (!((Map) v3).isEmpty() && !android.support.design.a.isTextEmpty(((String) v0_1))
                && !android.support.design.a.isTextEmpty(((String) v1))
                && !android.support.design.a.isTextEmpty(((String) v2))) {
            if (Logger.debug()) {
                Logger.d("PushConfigHelper", "tryRegistAllpush: 最终通道 = " + arg9);
            }
            SsPushManager.inst().handleAppLogUpdate(arg8, arg9, ((Map) v3));
        } else {
            Logger.d("PushConfigHelper", "tryRegistAllpush: ssid 错误");
        }
    }
}

